package DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zelonghu on 2019/3/29.
 */

public class dateutils {
    /*
     * 将时间转换为时间戳
     */
    public static String dateToStamp(String s,String pattern) throws ParseException {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        res = String.valueOf(ts);
        return res;
    }

    /*
    * 将时间戳转换为北京时间
    * @para s 时间戳的String类型
    *       pattern 要展示的形态 例如"HH:mm:ss"
    * @ret
    */
    public static String stampToDate(String s,String pattern){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        long lt = new Long(s);
        lt  += 8 * 60 * 60 * 1000;
        Date date = new Date(lt);
        res = simpleDateFormat.format(date);
        return res;
    }
}
